<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生管理</title>
    <!--框架必需start-->
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/qui/libs/js/jquery.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/qui/libs/js/language/cn.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/qui/libs/js/framework.js"></script>
    <link href="${pageContext.request.contextPath}/static/qui/libs/css/import_basic.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" id="skin" prePath="${pageContext.request.contextPath}/static/qui/" />
    <link rel="stylesheet" type="text/css" id="customSkin" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/qui/libs/js/popup/toast.js"></script>
    <script src="${pageContext.request.contextPath}/static/qui/libs/js/table/quiGrid.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/static/qui/libs/js/form/form.js" type="text/javascript"></script>

    <!--框架必需end-->
    <style type="text/css">
        .l-grid-row-cell-inner{
            margin-right: 1px;
        }
        .maingrid_content{
            position: absolute;
            top: 0;
            right: 0;
            width: 50%;
            height: 100%;
            border: 1px solid #EEEEEE;
            z-index: 99999;
            margin-right: -100%;
            box-shadow: -1px 0 3px #d3d8db;
            display: none;
        }
        .oppContent{
            width: 340px;
            height: 40px;
            float: left;
        }
    </style>
</head>
<body>
<div class="page_content">
    <div class="oppContent">
        <div class="buttonGroup" style="width: 80px;">
            <span class="leftButton icon_add" onclick="addStudent()">新增</span>
        </div>
    </div>

    <div class="searchContent">
        <form  id="queryForm" method="post">
            <table style="float: right;">
                <tr>
                    <td>
                             <input type="text" placeholder ="学号" id="stuNo" name="stuNo" />
                             <input type="text" placeholder ="学生姓名" id="stuName" name="stuName" />
                    </td>
                    <td><button type="button" id="search" class="primary" onclick="searchHandler()"><span class="icon_find">查询</span></button></td>
                    <td><button type="button" onclick="resetSearch()"><span class="icon_clear">重置</span></button></td>
                </tr>
            </table>
        </form>
    </div>
    <div class="clear"></div>
    <div id="dataBasic"></div>
</div>
<script>
    var grid = null;
    function initComplete() {
        grid = $("#dataBasic").quiGrid({
            columns: [
                    {display: '宿舍', name: 'dormNo', width: 200},
                    {display: '学号', name: 'stuNo', width: 200},
                    {display: '学生姓名', name: 'stuName', width: 200},
                    {display: '学生年级', name: 'stuYear', width: 200},
                    {display: '学生班别', name: 'stuClass', width: 200},
                    {display: '学生联系方式', name: 'stuPhone', width: 200},
                {
                    display: '操作', isAllowHide: false, width: 150,
                    render: function (rowdata, rowindex, value, column) {
                        return '<div class="grid_opp_container">'
                            + '<span class="grid_opp_edit" onclick="eidtStudent(\'' + rowdata.id + '\')">修改</span>'
                            + '<span class="grid_opp_delete" onclick="deleteStudent(\'' + rowdata.id + '\',' + rowindex + ')">删除</span>'
                            + '</div>';
                    }
                }
            ],
            url: '/student/getPageList', rownumbers: true, checkbox: true,
            height: '100%', width: "100%", pageSize: 10
        });
    }

    function addStudent() {
        var diag = new top.Dialog();
        diag.Title = "新增学生管理";
        diag.URL = "/admin/xsxt/studentForm.jsp?flag=add";
        diag.Width=600;
        diag.Height=400;
        diag.OkButtonText = "保存";
        diag.OKEvent = function() {
            diag.innerFrame.contentWindow.submitHandler(0);
        };
        diag.show();
    }

    function eidtStudent(id) {
        var diag = new top.Dialog();
        diag.Title = "修改学生管理";
        diag.URL = "/admin/xsxt/studentForm.jsp?flag=edit&id="+id;
        diag.Width=600;
        diag.Height=400;
        diag.OkButtonText = "保存";
        diag.OKEvent = function() {
            diag.innerFrame.contentWindow.submitHandler(0);
        };
        diag.show();
    }

    function deleteStudent(id) {
        top.Dialog.confirm("确认删除吗？",function(){
            $.post("/student/deleteStudent",{"id":id},function (data) {
                if(data.success){
                    top.Toast('showSuccessToast', data.msg);
                    refresh();
                }
                else{
                    top.Toast('showWarningToast', data.msg);
                }
            });
        });
    }

    //查询
    function searchHandler(){
        var query = $("#queryForm").formToArray();
        grid.setOptions({ params : query});
        //页号重置为1
        grid.setNewPage(1);
        grid.loadData();//加载数据
    }


    //重置查询
    function resetSearch(){
        $("#queryForm")[0].reset();
        $('#search').click();
    }

    function refresh(){
        grid.setNewPage(1);
        grid.loadData();
    }

</script>
</body>
</html>
